<template>
  <div style="width: 140px" class="flex gap-x-4 justify-center items-center">
    <div v-for="(item, key) in getColorList" :key="key" @click="selectItem(item)">
      <div :class="['color-' + item]" class="color-item flex justify-center items-center">
        <CheckOutlined v-if="model === item" />
      </div>
    </div>
    <div>
      <input v-model="model" v-admin type="color" class="w-[24px] inline-flex" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { getColorList } from '@/views/board/core-canvas/modules/data/common';

const model = defineModel('modelValue');
const emits = defineEmits(['change']);

const selectItem = (item: string) => {
  model.value = item;
  emits('change', item);
};
</script>

<style lang="scss" scoped>
.color-item {
  width: 20px;
  height: 20px;
  cursor: pointer;
  border-radius: 4px;
}
.color-red {
  background-color: red;
  color: white;
}
.color-yellow {
  background-color: yellow;
  color: white;
}
.color-black {
  background-color: black;
  color: white;
}
.color-transparent {
  background-color: transparent;
  border: 1px solid black;
  background-position:
    0px 0px,
    10px 10px;
  // 控制马赛克格子大小
  background-size: 4px 4px;
  background-image: linear-gradient(
      45deg,
      #eee 25%,
      transparent 25%,
      transparent 75%,
      #eee 75%,
      #333 100%
    ),
    linear-gradient(45deg, #eee 25%, white 25%, white 75%, #eee 75%, #333 100%);
}
.color-white {
  background-color: white;
  border: 1px solid black;
}
</style>
